home *** CD-ROM | disk | FTP | other *** search
/ C/C++ 3D Game Tools / C-C++ 3D Game Tools.iso / tools / algorith.txt / text0000.txt < prev   
Encoding:
Text File  |  1997-02-25  |  48.2 KB  |  1,371 lines

  1. Archive-name:       graphics/algorithms-faq
  2. Version:           1.14
  3. Last-Modified:     September 29, 1994
  4. Posting-Frequency: monthly
  5.  
  6.  
  7.  
  8. Welcome to the FAQ for comp.graphics.algorithms!
  9.  
  10. Thanks to all who have contributed.  Corrections and contributions
  11. always welcome.
  12.  
  13. Changed items are marked with a |.
  14. New items are marked with a +.
  15. Items needing input are marked with a ?.
  16.  
  17. All ftp    references are of the form ftp://node/path
  18. All Mosaic references are of the form http://node/path
  19.  
  20. ----------------------------------------------------------------------
  21. Table of Contents
  22. ----------------------------------------------------------------------
  23.  
  24.    0) Charter of comp.graphics.algorithms
  25. |  1) Are the postings to comp.graphics.algorithms archived?
  26.    2) What are some must have books on graphics algorithms?
  27.    3) Are there any online references?
  28.    4) Where is all the source?
  29.    5) How do I rotate a 2D point?
  30.    6) How do I rotate a 3D point?
  31.    7) How do I find the distance from a point to a line?
  32.    8) How do I find intersections of 2 2D line segments?
  33.    9) How do I find the intersection of a line and a plane?
  34.   10) How do I rotate a bitmap?
  35.   11) How do I display a 24 bit image in 8 bits?
  36.   12) How do I fill the area an arbitrary shape?
  37.   13) How do I find the 'edges' in a bitmap?
  38. ? 14) How do I enlarge/sharpen/fuzz a bitmap?
  39.   15) How do I map a texture on to a shape?
  40.   16) How do I find the area/orientation of a polygon?
  41.   17) How do I find if a point lies within a polygon?
  42. ? 18) How do I find the intersection of two convex polygons?
  43.   19) How do I detect a 'corner' in a collection of points?
  44.   20) How do I generate a circle through three points?
  45.   21) How do I generate a bezier curve that is parallel to another bezier?
  46.   22) How do I split a bezier at a specific value for t?
  47.   23) How do I find a t value at a specific point on a bezier?
  48.   24) How do I fit a bezier curve to a circle?
  49.   25) What is ARCBALL?
  50.   26) Where can I find ARCBALL source?
  51.   27) How do I clip a polygon against a rectangle?
  52.   28) How do I clip a polygon against another polygon?
  53. ? 29) Where can I get source for Weiler/Atherton clipping?
  54. ? 30) How do I generate a spline to approximate (insert curve here)?
  55. ? 31) Where do I get source to display (raster font format)?
  56. ? 32) What is morphing/how is it done?
  57. ? 33) How do I draw an anti-aliased line/polygon/ellipse?
  58.   34) How do I determine the intersection between a ray and a polygon?
  59.   35) How do I determine the intersection between a ray and a sphere?
  60.   36) How do I determine the intersection between a ray and a bezier surface?
  61.   37) How do I ray trace caustics?
  62.   38) How do I quickly draw a filled triangle?
  63.   39) Where can I get source for Voronoi/Delaunay triangulation?
  64.   40) Where do I get source for convex hull?
  65.   41) What is the marching cubes algorithm?
  66. ? 42) What is the status of the patent on the "marching cubes" algorithm?
  67.   43) How do I do a hidden surface test (backface culling) with 3d points?
  68.   44) How do I do a hidden surface test (backface culling) with 2d points?
  69.   45) Where can I find graph layout algorithms?
  70. ? 46) Where can I find algorithms for 2D collision detection?
  71.   47) Where can I find algorithms for 3D collision detection?
  72.   48) 3D Noise functions and turbulence in Solid texturing.
  73.   49) How do I perform basic viewing in 3d?
  74. ? 50) How can you contribute to this FAQ?
  75.   51) Contributors.  Who made this all possible.
  76.  
  77. ----------------------------------------------------------------------
  78.  
  79. Subject: 0) Charter of comp.graphics.algorithms
  80.  
  81.     Comp.graphics.algorithms is an unmoderated newsgroup intended
  82.     as a forum for the discussion of the algorithms used in the
  83.     process of generating computer graphics.  These algorithms may
  84.     be recently proposed in published journals or papers, old or
  85.     previously known algorithms, or hacks used incidental to the
  86.     process of computer graphics.  The scope of these algorithms
  87.     may range from an efficient way to multiply matrices, all the
  88.     way to a global illumination method incorporating ray tracing,
  89.     radiosity, infinite spectrum modeling, and perhaps even
  90.     mirrored balls and lime jello.
  91.  
  92.     It is hoped that this group will serve as a forum for programmers
  93.     and researchers to exchange ideas and ask questions on recent
  94.     papers or current research related to computer graphics.
  95.  
  96.     comp.graphics.algorithms is not:
  97.  
  98.      - for requests for gifs, or other pictures
  99.      - for requests for image translator software (i.e. gif <--> jpg)
  100.  
  101. ----------------------------------------------------------------------
  102.  
  103. Subject: 1) Are the postings to comp.graphics.algorithms archived?
  104.  
  105. |   Yes.  The "official" archive is stored at:
  106. |
  107. |     http://www.cis.ohio-state/hypertext/faq/usenet/graphics/algorithms-faq/faq.html
  108. |     ftp://rtfm.mit.edu/pub/usenet-by-group/news.answers/graphics/algorithms-faq
  109. |
  110. |   Also available at:
  111. |
  112. |     ftp://wuarchive.wustl.edu/graphics/graphics/mail-lists/comp.graphics.algorithms
  113.  
  114.     It is archived in the same manner that all other newsgroups are
  115.     being archived there, namely there is an Index file with all the
  116.     subjects, and all the articles are being kept in a hierarchy based
  117.     on the year and month they are posted.
  118.  
  119. |   FYI, all usenet FAQ's are available with Mosaic via
  120. |
  121. |   http://www.cis.ohio-state/hypertext/faq/usenet/top.html
  122.  
  123.  
  124. ----------------------------------------------------------------------
  125.  
  126. Subject: 2) What are some must have books on graphics algorithms?
  127.  
  128.     The keywords in brackets are used to refer to the books in later
  129.     questions.  They generally refer to the first author except where
  130.     it is necessary to resolve ambiguity or in the case of the Gems.
  131.  
  132.  
  133.     Basic computer graphics, rendering algorithms,
  134.     ----------------------------------------------
  135.  
  136.     [Foley]
  137.     Computer Graphics: Principles and Practice (2nd Ed.),
  138.     J.D. Foley, A. van Dam, S.K. Feiner, J.F. Hughes, Addison-Wesley
  139.     1990, ISBN 0-201-12110-7
  140.  
  141.     [Rogers:Procedural]
  142.     Procedural Elements for Computer Graphics,
  143.     David F. Rogers, McGraw Hill 1985, ISBN 0-07-053534-5
  144.  
  145.     [Rogers:Mathematical]
  146.     Mathematical Elements for Computer Graphics 2nd Ed.,
  147.     David F. Rogers and J. Alan Adams, McGraw Hill 1990, ISBN
  148.     0-07-053530-2
  149.  
  150.     [Watt:3D]
  151.     _3D Computer Graphics, 2nd Edition_,
  152.     Alan Watt, Addison-Wesley 1993, ISBN 0-201-63186-5
  153.  
  154.     [Glassner:RayTracing]
  155.     An Introduction to Ray Tracing,
  156.     Andrew Glassner (ed.), Academic Press 1989, ISBN 0-12-286160-4
  157.  
  158.     [Gems I]
  159.     Graphics Gems,
  160.     Andrew Glassner (ed.), Academic Press 1990, ISBN 0-12-286165-5
  161.  
  162.     [Gems II]
  163.     Graphics Gems II,
  164.     James Arvo (ed.), Academic Press 1991, ISBN 0-12-64480-0
  165.  
  166.     [Gems III]
  167.     Graphics Gems III,
  168.     David Kirk (ed.), Academic Press 1992, ISBN 0-12-409670-0 (with
  169.     IBM disk) or 0-12-409671-9 (with Mac disk)
  170.  
  171.     [Gems IV]
  172.     Graphics Gems IV,
  173.     Paul S. Heckbert (ed.), Academic Press 1994, ISBN 0-12-336155-9
  174.     (with IBM disk) or 0-12-336156-7 (with Mac disk)
  175.  
  176.     [Watt:Animation]
  177.     Advanced Animation and Rendering Techniques,
  178.     Alan Watt, Mark Watt, Addison-Wesley 1992, ISBN 0-201-54412-1
  179.  
  180.     [Bartels]
  181.     An Introduction to Splines for Use in Computer Graphics and
  182.         Geometric Modeling,
  183.     Richard H. Bartels, John C. Beatty, Brian A. Barsky, 1987, ISBN
  184.     0-934613-27-3
  185.  
  186.     [Farin]
  187.     Curves and Surfaces for Computer Aided Geometric Design:
  188.     A Practical Guide, 3rd Edition, Gerald E. Farin, Academic Press
  189.     1993. ISBN 0-12-249052-5
  190.  
  191.     [Prusinkiewicz]
  192.     The Algorithmic Beauty of Plants,
  193.     Przemyslaw W. Prusinkiewicz, Aristid Lindenmayer, Springer-Verlag,
  194.     1990, ISBN 0-387-97297-8, ISBN 3-540-97297-8
  195.  
  196.     [Oliver]
  197.     Tricks of the Graphics Gurus,
  198.     Dick Oliver, et al. (2) 3.5 PC disks included, $39.95 SAMS Publishing
  199.  
  200.     [Hearn]
  201.     Introduction to computer graphics,
  202.     Hearn & Baker
  203.  
  204.  
  205.     For image processing,
  206.     ---------------------
  207.  
  208.     [Barnsley]
  209.     Fractal Image Compression,
  210.     Michael F. Barnsley and Lyman P. Hurd, AK Peters, Ltd, 1993 ISBN
  211.     1-56881-000-8
  212.  
  213.     [Jain]
  214.     Fundamentals of Image Processing,
  215.     Anil K. Jain, Prentice-Hall 1989, ISBN 0-13-336165-9
  216.  
  217.     [Castleman]
  218.     Digital Image Processing,
  219.     Kenneth R. Castleman, Prentice-Hall 1979, ISBN 0-13-212365-7
  220.  
  221.     [Pratt]
  222.     Digital Image Processing, Second Edition,
  223.     William K. Pratt, Wiley-Interscience 1991, ISBN 0-471-85766-1
  224.  
  225.     [Gonzalez]
  226.     Digital Image Processing (2nd Ed.),
  227.     Rafael C. Gonzalez, Paul Wintz, Addison-Wesley 1987, ISBN
  228.     0-201-11026-1
  229.  
  230.     [Russ]
  231.     The Image Processing Handbook,
  232.     John C. Russ, CRC Press 1992, ISBN 0-8493-4233-3
  233.  
  234.     [Wolberg]
  235.     Digital Image Warping,
  236.     George Wolberg, IEEE Computer Society Press Monograph 1990, ISBN
  237.     0-8186-8944-7
  238.  
  239.  
  240.     Computational geometry,
  241.     ----------------------
  242.  
  243.     [Bowyer]
  244.     A Programmer's Geometry,
  245.     Adrian Bowyer, John Woodwark, Butterworths 1983, ISBN
  246.     0-408-01242-0 Pbk
  247.  
  248.     [O' Rourke]
  249.     Computational Geometry in C,
  250.     Joseph O'Rourke, Cambridge University Press 1994, ISBN
  251.     0-521-44592-2 Pbk, ISBN 0-521-44034-3 Hdbk
  252.  
  253.     [Mortenson]
  254.     Geometric Modeling,
  255.     Michael E. Mortenson, Wiley 1985, ISBN 0-471-88279-8
  256.  
  257.     [Preparata]
  258.     Computational Geometry: An Introduction,
  259.     Franco P. Preparata, Michael Ian Shamos, Springer-Verlag 1985,
  260.     ISBN 0-387-96131-3
  261.  
  262.  
  263. ----------------------------------------------------------------------
  264.  
  265. Subject: 3) Are there any online references?
  266.  
  267.     The computational geometry community maintains its own
  268.     bibliography of publications in or closely related to that
  269.     subject.  Every four months, additions and corrections are
  270.     solicited from users, after which the database is updated and
  271.     released anew.  As of September 1993, it contained 5356 bib-tex
  272.     entries.  It can be retrieved from
  273.  
  274.     ftp://cs.usask.ca/pub/geometry/geombib.tar.Z - bibliography proper
  275.  
  276.     ftp://cs.usask.ca/pub/geometry/geom.ps.Z     - PostScript format
  277.  
  278.     ftp://cs.usask.ca/pub/geometry/o-cgc19.ps.Z     - overview published
  279.         in '93 in SIGACT News and the Internat. J. Comput.  Geom. Appl.
  280.  
  281.     ftp://cs.usask.ca/pub/geometry/ftp-hints     - detailed retrieval info
  282.  
  283.     Announcing the ACM SIGGRAPH Online Bibliography Project, by
  284.     Stephen Spencer (biblio@siggraph.org)
  285.  
  286.     The database is available for anonymous FTP from the
  287.     ftp://siggraph.org/publications/bibliography directory.  Please
  288.     download and examine the file READ_ME in that directory for more
  289.     specific information concerning the database.
  290.  
  291.     'netlib' is a useful source for algorithms, member inquiries for
  292.     SIAM, and bibliographic searches.  For information, send mail to
  293.     netlib@ornl.gov, with "send index" in the body of the mail
  294.     message.
  295.  
  296.     You can also find free sources for numerical computation in C via
  297.     ftp://usc.edu/pub/C-numanal.  In particular, grab
  298.     numcomp-free-c.gz in that directory. 
  299.  
  300.     Check out Nick Fotis's computer graphics resources FAQ -- it's
  301.     packed with pointers to all sorts of great computer graphics
  302.     stuff.  This FAQ is posted biweekly to comp.graphics.
  303.  
  304.  
  305. ----------------------------------------------------------------------
  306.  
  307. Subject: 4) Where is all the source?
  308.  
  309.     Graphics Gems source code.
  310.     ftp://princeton.edu:pub/Graphics/GraphicsGems
  311.  
  312.     General 'stuff'
  313.     ftp://wuarchive.wustl.edu/graphics/graphics
  314.  
  315.  
  316. ----------------------------------------------------------------------
  317.  
  318. Subject: 5) How do I rotate a 2D point?
  319.  
  320.     In 2-D, the 2x2 matrix is very simple.  If you want to rotate a
  321.     column vector v by t degrees using matrix M, use
  322.  
  323.         M = {{cos t, -sin t}, {sin t, cos t}} in M*v.
  324.  
  325.     If you have a row vector, use the transpose of M (turn rows into
  326.     columns and vice versa).  If you want to combine rotations, in 2-D
  327.     you can just add their angles, but in higher dimensions you must
  328.     multiply their matrices.
  329.  
  330.  
  331. ----------------------------------------------------------------------
  332.  
  333. Subject: 6) How do I rotate a 3D point?
  334.  
  335.     Assuming you want to rotate vectors around the origin of your
  336.     coordinate system. (If you want to rotate around some other point,
  337.     subtract its coordinates from the point you are rotating, do the
  338.     rotation, and then add back what you subtracted.) In 3-D, you need
  339.     not only an angle, but also an axis. (In higher dimensions it gets
  340.     much worse, very quickly.)  Actually, you need 3 independent
  341.     numbers, and these come in a variety of flavors.  The flavor I
  342.     recommend is unit quaternions: 4 numbers that square and add up to
  343.     +1.  You can write these as [(x,y,z),w], with 4 real numbers, or
  344.     [v,w], with v, a 3-D vector pointing along the axis. The concept
  345.     of an axis is unique to 3-D. It is a line through the origin
  346.     containing all the points which do not move during the rotation.
  347.     So we know if we are turning forwards or back, we use a vector
  348.     pointing out along the line. Suppose you want to use unit vector u
  349.     as your axis, and rotate by 2t degrees.  (Yes, that's twice t.)
  350.     Make a quaternion [u sin t, cos t]. You can use the quaternion --
  351.     call it q -- directly on a vector v with quaternion
  352.     multiplication, q v q^-1, or just convert the quaternion to a 3x3
  353.     matrix M. If the components of q are {(x,y,z),w], then you want
  354.     the matrix
  355.  
  356.         M = {{1-2(yy+zz),  2(xy-wz),  2(xz+wy)},
  357.              {  2(xy+wz),1-2(xx+zz),  2(yz-wx)},
  358.              {  2(xz-wy),  2(yz+wx),1-2(xx+yy)}}.
  359.  
  360.     Rotations, translations, and much more are explained in all basic
  361.     computer graphics texts.  Quaternions are covered briefly in
  362.     [Foley], and more extensively in several Graphics Gems, and the
  363.     SIGGRAPH 85 proceedings.
  364.  
  365.  
  366. ----------------------------------------------------------------------
  367.  
  368. Subject: 7) How do I find the distance from a point to a line?
  369.  
  370.  
  371.     Let the point be C (XC,YC) and the line be AB (XA,YA) to (XB,YB).
  372.     The length of the line segment AB is L:
  373.  
  374.         L=((XB-XA)**2+(YB-YA)**2)**0.5
  375.  
  376.     and
  377.             (YA-YC)(YA-YB)-(XA-XC)(XB-XA)
  378.         r = -----------------------------
  379.                         L**2
  380.  
  381.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  382.         s = -----------------------------
  383.                         L**2
  384.  
  385.     Let I be the point of perpendicular projection of C onto AB, the
  386.  
  387.         XI=XA+r(XB-XA)
  388.         YI=YA+r(YB-YA)
  389.  
  390.     Distance from A to I = r*L
  391.     Distance from C to I = s*L
  392.  
  393.     If r<0      I is on backward extension of AB
  394.     If r>1      I is on ahead extension of AB
  395.     If 0<=r<=1  I is on AB
  396.  
  397.     If s<0      C is left of AB (you can just check the numerator)
  398.     If s>0      C is right of AB
  399.     If s=0      C is on AB
  400.  
  401.  
  402. ----------------------------------------------------------------------
  403.  
  404. Subject: 8) How do I find intersections of 2 2D line segments?
  405.  
  406.     This problem can be extremely easy or extremely difficult depends
  407.     on your applications.  If all you want is the intersection point,
  408.     the following should work:
  409.  
  410.     Let A,B,C,D be 2-space position vectors.  Then the directed line
  411.     segments AB & CD are given by:
  412.  
  413.         AB=A+r(B-A), r in [0,1]
  414.         CD=C+s(D-C), s in [0,1]
  415.  
  416.     If AB & CD intersect, then
  417.  
  418.         A+r(B-A)=C+s(D-C), or
  419.  
  420.         XA+r(XB-XA)=XC+s(XD-XC)
  421.         YA+r(YB-YA)=YC+s(YD-YC)  for some r,s in [0,1]
  422.  
  423.     Solving the above for r and s yields
  424.  
  425.             (YA-YC)(XD-XC)-(XA-XC)(YD-YC)
  426.         r = -----------------------------  (eqn 1)
  427.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  428.  
  429.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  430.         s = -----------------------------  (eqn 2)
  431.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  432.  
  433.     Let I be the position vector of the intersection point, then
  434.  
  435.         I=A+r(B-A) or
  436.  
  437.         XI=XA+r(XB-XA)
  438.         YI=YA+r(YB-YA)
  439.  
  440.     By examining the values of r & s, you can also determine some
  441.     other limiting conditions:
  442.  
  443.         If 0<=r<=1 & 0<=s<=1, intersection exists
  444.             r<0 or r>1 or s<0 or s>1 line segments do not intersect
  445.  
  446.         If the denominator in eqn 1 is zero, AB & CD are parallel
  447.         If the numerator in eqn 1 is also zero, AB & CD are coincident
  448.  
  449.     If the intersection point of the 2 lines are needed (lines in this
  450.     context mean infinite lines) regardless whether the two line
  451.     segments intersect, then
  452.  
  453.         If r>1, I is located on extension of AB
  454.         If r<0, I is located on extension of BA
  455.         If s>1, I is located on extension of CD
  456.         If s<0, I is located on extension of DC
  457.  
  458.     Also note that the denominators of eqn 1 & 2 are identical.
  459.  
  460.     References:
  461.  
  462.     [O'Rourke] pp. 249-51
  463.     [Gems III] pp. 199-202 "Faster Line Segment Intersection,"
  464.  
  465.  
  466. ----------------------------------------------------------------------
  467.  
  468. Subject: 9) How do I find the intersection of a line and a plane?
  469.  
  470.     If the plane is defined as:
  471.  
  472.         a*x + b*y + c*z + d = 0
  473.  
  474.     and the line is defined as:
  475.  
  476.         x = x1 + (x2 - x1)*t = x1 + i*t
  477.         y = y1 + (y2 - y1)*t = y1 + j*t
  478.         z = z1 + (z2 - z1)*t = z1 + k*t
  479.  
  480.     Then just substitute these into the plane equation. You end up
  481.     with:
  482.  
  483.         t = - (a*x1 + b*y1 + c*z1 + d)/(a*i + b*j + c*k)
  484.  
  485.     If the denominator is zero, then the vector (a,b,c) and the vector
  486.     (i,j,k) are perpendicular.  Note that (a,b,c) is the normal to the
  487.     plane and (i,j,k) is the direction of the line.  It follows that
  488.     the line is either parallel to the plane or contained in the
  489.     plane. In either case there is no unique intersection point.
  490.  
  491.  
  492. ----------------------------------------------------------------------
  493.  
  494. Subject: 10) How do I rotate a bitmap?
  495.  
  496.     The easiest way, according to the comp.graphics faq, is to take
  497.     the rotation transformation and invert it. Then you just iterate
  498.     over the destination image, apply this inverse transformation and
  499.     find which source pixel to copy there.
  500.  
  501.     A much nicer way comes from the observation that the rotation
  502.     matrix:
  503.  
  504.         R(T) = { { cos(T), -sin(T) }, { sin(T), cos(T) } }
  505.  
  506.     is formed my multiplying three matrices, namely:
  507.  
  508.         R(T) = M1(T) * M2(T) * M3(T)
  509.  
  510.     where
  511.  
  512.         M1(T) = { { 1, -tan(T/2) },
  513.                   { 0, 1         } }
  514.         M2(T) = { { 1,      0    },
  515.                   { sin(T), 1    } }
  516.         M3(T) = { { 1, -tan(T/2) },
  517.                   { 0,         1 } }
  518.  
  519.     Each transformation can be performed in a separate pass, and
  520.     because these transformations are either row-preserving or
  521.     column-preserving, anti-aliasing is quite easy.
  522.  
  523.     Reference:
  524.  
  525.     Paeth, A. W., "A Fast Algorithm for General Raster Rotation",
  526.     Proceedings Graphics Interface '89, Canadian Information
  527.     Processing Society, 1986, 77-81
  528.     [Note - e-mail copies of this paper are no longer available]
  529.  
  530.     [Gems I]
  531.  
  532.  
  533. ----------------------------------------------------------------------
  534.  
  535. Subject: 11) How do I display a 24 bit image in 8 bits?
  536.  
  537.     [Gems I] pp. 287-293, "A Simple Method for Color Quantization:
  538.     Octree Quantization"
  539.  
  540.     B. Kurz.  Optimal Color Quantization for Color Displays.
  541.     Proceedings of the IEEE Conference on Computer Vision and Pattern
  542.     Recognition, 1983, pp. 217-224.
  543.  
  544.     [Gems II] pp. 116-125, "Efficient Inverse Color Map Computation"
  545.  
  546.         This describes an efficient technique to
  547.         map actual colors to a reduced color map,
  548.         selected by some other technique described
  549.         in the other papers.
  550.  
  551.     [Gems II] pp. 126-133, "Efficient Statistical Computations for
  552.     Optimal Color Quantization"
  553.  
  554.     Xiaolin Wu.  Color Quantization by Dynamic Programming and
  555.     Principal Analysis.  ACM Transactions on Graphics, Vol. 11, No. 4,
  556.     October 1992, pp 348-372.
  557.  
  558.  
  559. ----------------------------------------------------------------------
  560.  
  561. Subject: 12) How do I fill the area of an arbitrary shape?
  562.  
  563.  
  564.     "A Fast Algorithm for the Restoration of Images Based on Chain
  565.         Codes Description and Its Applications", L.W. Chang & K.L. Leu,
  566.         Computer Vision, Graphics, and Image Processing, vol.50,
  567.         pp296-307 (1990)
  568.  
  569.     "An Introductory Course in Computer Graphics" by Richard Kingslake,
  570.         (2nd edition) published by Chartwell-Bratt ISBN 0-86238-284-X
  571.  
  572.     [Gems I]
  573.     [Foley]
  574.     [Hearn]
  575.  
  576.  
  577. ----------------------------------------------------------------------
  578.  
  579. Subject: 13) How do I find the 'edges' in a bitmap?
  580.  
  581.     A simple method is to put the bitmap through the filter:
  582.  
  583.         -1    -1    -1
  584.         -1     8    -1
  585.         -1    -1    -1
  586.  
  587.     This will highlight changes in contrast.  Then any part of the
  588.     picture where the absolute filtered value is higher than some
  589.     threshold is an "edge".
  590.  
  591.  
  592. ----------------------------------------------------------------------
  593.  
  594. Subject: 14) How do I enlarge/sharpen/fuzz a bitmap?
  595.  
  596.  
  597. ----------------------------------------------------------------------
  598.  
  599. Subject: 15) How do I map a texture on to a shape?
  600.  
  601.     Paul S. Heckbert, "Survey of Texture Mapping", IEEE Computer
  602.     Graphics and Applications V6, #11, Nov. 1986, pp 56-67 revised
  603.     from Graphics Interface '86 version
  604.  
  605.     Eric A. Bier and Kenneth R. Sloan, Jr., "Two-Part Texture
  606.     Mappings", IEEE Computer Graphics and Applications V6 #9, Sept.
  607.     1986, pp 40-53 (projection parameterizations)
  608.  
  609.  
  610. ----------------------------------------------------------------------
  611.  
  612. Subject: 16) How do I find the area/orientation of a polygon?
  613.  
  614.     Compute the signed area.  The orientation is counter-clockwise if
  615.     this area is positive.  There's a Gem on computing signed areas.
  616.  
  617.     A slightly faster method is based on the observation that it isn't
  618.     necessary to compute the area.  One can find the lowest, rightmost
  619.     point of the polygon, and then take the cross product of the edges
  620.     fore and aft of it.  Both methods are O(n) for n vertices, but it
  621.     does seem a waste to add up the total area when a single cross
  622.     product (of just the right edges) suffices.
  623.  
  624.     The reason that the lowest, rightmost point works is that the
  625.     internal angle at this vertex is necessarily convex, strictly less
  626.     than pi (even if there are several equally-lowest points).
  627.  
  628.     The key formula is this:
  629.  
  630.         If the coordinates of vertex v_i are x_i and y_i,
  631.         twice the area of a polygon is given by
  632.  
  633.         2 A( P ) = sum_{i=0}^{n-1} (x_i y_{i+1} - y_i x_{i+1}).
  634.  
  635.     Reference:
  636.  
  637.     [O' Rourke] pp. 18-27.
  638.  
  639.  
  640. ----------------------------------------------------------------------
  641.  
  642. Subject: 17) How do I find if a point lies within a polygon?
  643.  
  644.     A quick comment - the code in the Sedgewick book Algorithms is
  645.     wrong.
  646.  
  647.     The short answer, for the FAQ, could be:
  648.  
  649.     int pnpoly(int npol, float *xp, float *yp, float x, float y)
  650.     {
  651.       int i, j, c = 0;
  652.       for (i = 0, j = npol-1; i < npol; j = i++) {
  653.         if ((((yp[i]<=y) && (y<yp[j])) ||
  654.              ((yp[j]<=y) && (y<yp[i]))) &&
  655.             (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
  656.           c = !c;
  657.       }
  658.       return c;
  659.     }
  660.  
  661.     This code is from Wm. Randolph Franklin, wrf@ecse.rpi.edu, a
  662.     professor at RPI, with some minor modifications for speed by me.
  663.     A good reference for this problem will be:
  664.  
  665.     References:
  666.  
  667.     [O'Rourke] pp. 233-238
  668.     [Gems IV]  pp. 23-45
  669.     [Glassner:RayTracing]
  670.  
  671.  
  672. ----------------------------------------------------------------------
  673.  
  674. Subject: 18) How do I find the intersection of two convex polygons?
  675.  
  676.     [O'Rourke] pp. 242-252
  677.  
  678.  
  679. ----------------------------------------------------------------------
  680.  
  681. Subject: 19) How do I detect a 'corner' in a collection of points?
  682.  
  683.     For the general solution to the problem get Ata Etemadi's software
  684.     package and associated  papers from one of the addresses below.
  685.     It's very fast and detects polygons too.
  686.  
  687.     ftp://peipa.essex.ac.uk/ipa/src/process
  688.     ftp://ftp.teleos.com/VISION-LIST-ARCHIVE/SHAREWARE
  689.  
  690.  
  691. ----------------------------------------------------------------------
  692.  
  693. Subject: 20) How do I generate a circle through three points?
  694.  
  695.     Let the three given points be a, b, c.  Use _0 and _1 to represent
  696.     x and y coordinates. The coordinates of the center p=(p_0,p_1) of
  697.     the circle determined by a, b, and c are:
  698.  
  699.             p_0 =
  700.                     ( b_1 a_0^2
  701.                     - c_1 a_0^2
  702.                     - b_1^2 a_1
  703.                     + c_1^2 a_1
  704.                     + b_0^2 c_1
  705.                     + a_1^2 b_1
  706.                     + c_0^2 a_1
  707.                     - c_1^2 b_1
  708.                     - c_0^2 b_1
  709.                     - b_0^2 a_1
  710.                     + b_1^2 c_1
  711.                     - a_1^2 c_1 )
  712.                 / D
  713.  
  714.             p_1 =
  715.                     ( a_0^2 c_0
  716.                     + a_1^2 c_0
  717.                     + b_0^2 a_0
  718.                     - b_0^2 c_0
  719.                     + b_1^2 a_0
  720.                     - b_1^2 c_0
  721.                     - a_0^2 b_0
  722.                     - a_1^2 b_0
  723.                     - c_0^2 a_0
  724.                     + c_0^2 b_0
  725.                     - c_1^2 a_0
  726.                     + c_1^2 b_0)
  727.                 / D
  728.  
  729.     where
  730.  
  731.             D = 2( a_1 c_0 + b_1 a_0 - b_1 c_0 -a_1 b_0 -c_1 a_0 + c_1 b_0 )
  732.  
  733.     The radius of the circle is then:
  734.  
  735.             r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2
  736.  
  737.     Reference:
  738.  
  739.     [O' Rourke] p. 201
  740.  
  741.  
  742. ----------------------------------------------------------------------
  743.  
  744. Subject: 21) How do I generate a bezier curve that is parallel to another bezier?
  745.  
  746.     You can't.  The only case where this is possible is when the
  747.     bezier can be represented by a straight line.  And then the
  748.     parallel 'bezier' can also be represented by a straight line.
  749.  
  750.  
  751. ----------------------------------------------------------------------
  752.  
  753. Subject: 22) How do I split a bezier at a specific value for t?
  754.  
  755.     A Bezier curve is a parametric polynomial function from the
  756.     interval [0..1] to a space, usually 2-D or 3-D.  Common Bezier
  757.     curves use cubic polynomials, so have the form
  758.  
  759.         f(t) = a3 t^3 + a2 t^2 + a1 t + a0,
  760.  
  761.     where the coefficients are points in 3-D. Blossoming converts this
  762.     polynomial to a more helpful form.  Let s = 1-t, and think of
  763.     tri-linear interpolation:
  764.  
  765.         F([s0,t0],[s1,t1],[s2,t2]) =
  766.             s0(s1(s2 c30 + t2 c21) + t1(s2 c21 + t2 c12)) +
  767.             t0(s1(s2 c21 + t2 c12) + t1(s2 c12 + t2 c03))
  768.             =
  769.             c30(s0 s1 s2) +
  770.             c21(s0 s1 t2 + s0 t1 s2 + t0 s1 s2) +
  771.             c12(s0 t1 t2 + t0 s1 t2 + t0 t1 s2) +
  772.             c03(t0 t1 t2).
  773.  
  774.     The data points c30, c21, c12, and c03 have been used in such a
  775.     way as to make the resulting function give the same value if any
  776.     two arguments, say [s0,t0] and [s2,t2], are swapped. When [1-t,t]
  777.     is used for all three arguments, the result is the cubic Bezier
  778.     curve with those data points controlling it:
  779.  
  780.           f(t) = F([1-t,t],[1-t,t],[1-t,t])
  781.                =  (1-t)^3 c30 +
  782.                  3(1-t)^2 t c21 +
  783.                  3(1-t) t^2 c12 +
  784.                  t^3 c03.
  785.  
  786.     Notice that
  787.            F([1,0],[1,0],[1,0]) = c30,
  788.            F([1,0],[1,0],[0,1]) = c21,
  789.            F([1,0],[0,1],[0,1]) = c12, _
  790.            F([0,1],[0,1],[0,1]) = c03.
  791.  
  792.     In other words, cij is obtained by giving F argument t's i of
  793.     which are 0 and j of which are 1. Since F is a linear polynomial
  794.     in each argument, we can find f(t) using a series of simple steps.
  795.     Begin with
  796.  
  797.         f000 = c30, f001 = c21, f011 = c12, f111 = c03.
  798.  
  799.     Then compute in succession:
  800.  
  801.         f00t = s f000 + t f001, f01t = s f001 + t f011,
  802.         f11t = s f011 + t f111,
  803.         f0tt = s f00t + t f01t, f1tt = s f01t + t f11t,
  804.         fttt = s f0tt + t f1tt.
  805.  
  806.     This is the de Casteljau algorithm for computing f(t) = fttt.
  807.  
  808.     It also has split the curve for the intervals [0..t] and [t..1].
  809.     The control points for the first interval are f000, f00t, f0tt,
  810.     fttt, while those for the second interval are fttt, f1tt, f11t,
  811.     f111.
  812.  
  813.     If you evaluate 3 F([1-t,t],[1-t,t],[-1,1]) you will get the
  814.     derivate of f at t. Similarly, 2*3 F([1-t,t],[-1,1],[-1,1]) gives
  815.     the second derivative of f at t, and finally using 1*2*3
  816.     F([-1,1],[-1,1],[-1,1]) gives the third derivative.
  817.  
  818.     This procedure is easily generalized to different degrees,
  819.     triangular patches, and B-spline curves.
  820.  
  821.  
  822. ----------------------------------------------------------------------
  823.  
  824. Subject: 23) How do I find a t value at a specific point on a bezier?
  825.  
  826.     In general, you'll need to find t closest to your search point.
  827.     There are a number of ways you can do this. Look at [Gems I, 607],
  828.     there's a chapter on finding the nearest point on the bezier
  829.     curve.  In my experience, digitizing the bezier curve is an
  830.     acceptable method. You can also try recursively subdividing the
  831.     curve, see if you point is in the convex hull of the control
  832.     points, and checking is the control points are close enough to a
  833.     linear line segment and find the nearest point on the line
  834.     segment, using linear interpolation and keeping track of the
  835.     subdivision level, you'll be able to find t.
  836.  
  837.  
  838. ----------------------------------------------------------------------
  839.  
  840. Subject: 24) How do I fit a bezier curve to a circle?
  841.  
  842.     Interestingly enough, bezier curves can approximate a circle but
  843.     not perfectly fit a circle.
  844.  
  845.     Michael Goldapp, "Approximation of circular arcs by cubic
  846.     polynomials" Computer Aided Geometric Design (#8 1991 pp.227-238)
  847.  
  848.     Tor Dokken and Morten Daehlen, "Good Approximations of circles by
  849.     curvature-continuous Bezier curves" Computer Aided Geometric
  850.     Design (#7 1990 pp. 33-41).
  851.  
  852.  
  853. ----------------------------------------------------------------------
  854.  
  855. Subject: 25) What is ARCBALL?
  856.  
  857.     Arcball is a general purpose 3-D rotation controller described by
  858.     Ken Shoemake in the Graphics Interface '92 Proceedings.  It
  859.     features good behavior, easy implementation, cheap execution, and
  860.     optional axis constraints. A Macintosh demo and electronic version
  861.     of the original paper (Microsoft Word format) may be obtained from
  862.     ftp::/ftp.cis.upenn.edu/pub/graphics.
  863.  
  864.  
  865. ----------------------------------------------------------------------
  866.  
  867. Subject: 26) Where can I find ARCBALL source?
  868.  
  869.     Complete source code appears in Graphics Gems IV pp. 175-192. A
  870.     fairly complete sketch of the code appeared in the original
  871.     article, in Graphics Interface 92 Proceedings, available from
  872.     Morgan Kaufmann.
  873.  
  874.  
  875. ----------------------------------------------------------------------
  876.  
  877. Subject: 27) How do I clip a polygon against a rectangle?
  878.  
  879.     This is the Sutherland-Hodgman algorithm, an old favorite that
  880.     should be covered in any textbook. Any of the references listed in
  881.     the FAQ should have it.  According to Vatti (q.v.)  "This
  882.     [algorithm] produces degenerate edges in certain concave / self
  883.     intersecting polygons that need to be removed as a special
  884.     extension to the main algorithm" (though this is not a problem if
  885.     all you are doing with the results is scan converting them.)
  886.  
  887.  
  888. ----------------------------------------------------------------------
  889.  
  890. Subject: 28) How do I clip a polygon against another polygon?
  891.  
  892.     People interested in some alpha state code, written in C++ with
  893.     templates (for example: g++) can contact Klamer Schutte,
  894.     klamer@mi.el.utwente.nl.  Or with Mosaic, at
  895.     http://ph.tn.tudelft.nl:2000/People/klamer/Klamer.html#clippoly.
  896.     Also from ftp://galaxy.ph.tn.tudelft.nl/pub/klamer/clippoly.tar.gz
  897.  
  898.  
  899. ----------------------------------------------------------------------
  900.  
  901. Subject: 29) Where can I get source for Weiler/Atherton clipping?
  902.  
  903.  
  904. ----------------------------------------------------------------------
  905.  
  906. Subject: 30) How do I generate a spline to approximate (insert curve here)?
  907.  
  908.  
  909. ----------------------------------------------------------------------
  910.  
  911. Subject: 31) Where do I get source to display (raster font format)?
  912.  
  913.  
  914. ----------------------------------------------------------------------
  915.  
  916. Subject: 32) What is morphing/how is it done?
  917.  
  918.  
  919. ----------------------------------------------------------------------
  920.  
  921. Subject: 33)How do I draw an anti-aliased line/polygon/ellipse?
  922.  
  923.  
  924. ----------------------------------------------------------------------
  925.  
  926. Subject: 34) How do I determine the intersection between a ray and a polygon
  927.  
  928.     First find the intersection between the ray and the plane in which
  929.     the polygon is situated. Then see if the point of intersection is
  930.     in the polygon.
  931.  
  932.     Reference:
  933.  
  934.     [Glassner:RayTracing]
  935.  
  936.  
  937. ----------------------------------------------------------------------
  938.  
  939. Subject: 35) How do I determine the intersection between a ray and a sphere
  940.  
  941.     Given a ray defined as:
  942.  
  943.         x = x1 + (x2 - x1)*t = x1 + i*t
  944.         y = y1 + (y2 - y1)*t = y1 + j*t
  945.         z = z1 + (z2 - z1)*t = z1 + k*t
  946.  
  947.     and a sphere defined as:
  948.  
  949.         (x - l)**2 + (y - m)**2 + (z - n)**2 = r**2
  950.  
  951.     Substituting in gives the quadratic equation:
  952.  
  953.         a*t**2 + b*t + c = 0
  954.  
  955.     where:
  956.  
  957.         a = i**2 + j**2 + k**2
  958.         b = 2*i*(x1 - l) + 2*j*(y1 - m) + 2*k*(x1 - n)
  959.         c = l**2 + m**2 + n**2 + x1**2 + y1**2 + z1**2
  960.             - 2*(l*x1 + m*y1 + n*z1) - r**2
  961.  
  962.     If the determinant of this equation is less than 0, the line does
  963.     not intersect the sphere. If it is zero, the line is tangential to
  964.     the sphere and if it is greater than zero it intersects at two
  965.     points. Solving the equation and substituting the values of t into
  966.     the ray equation will give you the points.
  967.  
  968.     Reference:
  969.  
  970.     [Glassner:RayTracing]
  971.  
  972.  
  973. ----------------------------------------------------------------------
  974.  
  975. Subject: 36) How do I determine the intersection between a ray and a bezier
  976.              surface?
  977.  
  978.     Joy I.K. and Bhetanabhotla M.N., "Ray tracing parametric surfaces
  979.     utilizing numeric techniques and ray coherence", Computer
  980.     Graphics, 16, 1986, 279-286
  981.  
  982.     Joy and Bhetanabhotla is only one approach of three major method
  983.     classes: tessellation, direct computation, and a hybrid of the
  984.     two.  Tessellation is relatively easy (you intersect the polygons
  985.     making up the tessellation) and has no numerical problems, but can
  986.     be inaccurate; direct is cheap on memory, but very expensive
  987.     computationally, and can (and usually does) suffer from precision
  988.     problems within the root solver; hybrids try to blend the two.
  989.  
  990.     Reference:
  991.  
  992.     [Glassner:RayTracing]
  993.  
  994.  
  995. ----------------------------------------------------------------------
  996.  
  997. Subject: 37) How do I ray trace caustics?
  998.  
  999.     There is a discussion in [Watt:Animation], but I don't know how
  1000.     good it is.
  1001.  
  1002.     It's hard to get right.
  1003.  
  1004.     One right (but incredibly expensive) answer is:
  1005.  
  1006.     @InProceedings{mitchell-1992-illumination,
  1007.       author         = "Don P. Mitchell and Pat Hanrahan",
  1008.       title          = "Illumination From Curved Reflectors",
  1009.       year           = "1992",
  1010.       month          = "July",
  1011.       volume         = "26",
  1012.       booktitle      = "Computer Graphics (SIGGRAPH '92 Proceedings)",
  1013.       pages          = "283--291",
  1014.       keywords       = "caustics, interval arithmetic, ray tracing",
  1015.       editor         = "Edwin E. Catmull",
  1016.     }
  1017.  
  1018.     A cheat:
  1019.  
  1020.     @Article{inakage-1986-caustics,
  1021.       author         = "Masa Inakage",
  1022.       title          = "Caustics and Specular Reflection Models for
  1023.                         Spherical Objects and Lenses ",
  1024.       pages          = "379--383",
  1025.       journal        = "The Visual Computer",
  1026.       volume         = "2",
  1027.       number         = "6",
  1028.       year           = "1986",
  1029.       keywords       = "ray tracing effects",
  1030.     }
  1031.  
  1032.     very specialized:
  1033.  
  1034.     @Article{yuan-1988-gemstone,
  1035.       author         = "Ying Yuan and Tosiyasu L. Kunii and Naota
  1036.                         Inamato and Lining Sun ",
  1037.       title          = "Gemstone Fire: Adaptive Dispersive Ray Tracing
  1038.                         of Polyhedrons ",
  1039.       year           = "1988",
  1040.       month          = "November",
  1041.       journal        = "The Visual Computer",
  1042.       volume         = "4",
  1043.       number         = "5",
  1044.       pages          = "259--70",
  1045.       keywords       = "caustics",
  1046.     }
  1047.  
  1048.  
  1049. ----------------------------------------------------------------------
  1050.  
  1051. Subject: 38) How do I quickly draw a filled triangle?
  1052.  
  1053.     The easiest way is to render each line separately into an edge
  1054.     buffer. This buffer is a structure which looks like this (in C):
  1055.  
  1056.         struct { int xmin, xmax; } edgebuffer[YDIM];
  1057.  
  1058.     There is one entry for each scan line on the screen, and each
  1059.     entry is to be interpreted as a horizontal line to be drawn from
  1060.     xmin to xmax.
  1061.  
  1062.     Since most people who ask this question are trying to write fast
  1063.     games on the PC, I'll tell you where to find code.  Look at:
  1064.  
  1065.         ftp::/ftp.uwp.edu/pub/msdos/demos/programming/source
  1066.  
  1067.  
  1068. ----------------------------------------------------------------------
  1069.  
  1070. Subject: 39) Where can I get source for Voronoi/Delaunay triangulation?
  1071.  
  1072.     Source code in C for general dimension convex hull and Delaunay
  1073.     triangulation (qhull) is now available from:
  1074.  
  1075.         ftp://geom.umn.edu/pub/software/qhull.tar.Z
  1076.         ftp://geom.umn.edu/pub/software/qhull.sit.hqx for Macintosh
  1077.  
  1078.     You can view the results in 3-d and 4-d with geomview from:
  1079.  
  1080.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-sgi.tar.Z  - Iris
  1081.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-next.tar.Z - Next
  1082.  
  1083.     Convex hull is an easy way to build convex polytopes (just list
  1084.     the vertices).  The algorithm also produces approximate convex
  1085.     hulls.  For example, we have produced the approximate convex hull
  1086.     of 12,000 points in R^6, randomly distributed in the unit cube.
  1087.  
  1088.     The distribution includes .ps files for:
  1089.  
  1090.         Barber, C.B., Dobkin, D.P., and Huhdanpaa, H., "The Quickhull
  1091.         Algorithm for Convex Hull," Technical Report GCG53, The
  1092.         Geometry Center, Univ. of Minnesota, July 1993.
  1093.  
  1094.     References:
  1095.  
  1096.     [O' Rourke] pp. 168-204
  1097.     Three-dimensional convex hull C code in Chapter 4 (p.130-60).
  1098.  
  1099.  
  1100. ----------------------------------------------------------------------
  1101.  
  1102. Subject: 40) Where do I get source for convex hull?
  1103.  
  1104.     See the previous question on Delaunay triangulation.  The two are
  1105.     the same because the Delaunay triangulation of a set of points is
  1106.     the convex hull of the points lifted to a paraboloid.
  1107.  
  1108.     References:
  1109.     [O' Rourke] pp. 70-112
  1110.     C code for Graham's algorithm on p.80-96.
  1111.     Three-dimensional convex hull discussed in Chapter 4 (p.113-67).
  1112.     C code for the incremental algorithm on p.130-60.
  1113.  
  1114.  
  1115. ----------------------------------------------------------------------
  1116.  
  1117. Subject: 41) What is the marching cubes algorithm?
  1118.  
  1119.     The marching cubes algorithm is used in volume rendering to
  1120.     construct an isosurface from a 3D field of values.
  1121.  
  1122.     The 2D analog would be to take an image, and for each pixel, set
  1123.     it to black if the value is below some threshold, and set it to
  1124.     white if it's above the threshold.  Then smooth the jagged black
  1125.     outlines by skinning them with lines.
  1126.  
  1127.     The marching cubes algorithm tests the corner of each cube (or
  1128.     voxel) in the scalar field as being either above or below a given
  1129.     threshold.  This yields a collection of boxes with classified
  1130.     corners.  Since there are eight corners with one of two states,
  1131.     there are 256 different possible combinations for each cube.
  1132.     Then, for each cube, you replace the cube with a surface that
  1133.     meets the classification of the cube.  For example, the following
  1134.     are some 2D examples showing the cubes and their associated
  1135.     surface.
  1136.  
  1137.         - ----- +       - ----- -       - ----- +       - ----- +
  1138.         |:::'   |       |:::::::|       |::::   |       |   ':::|
  1139.         |:'     |       |:::::::|       |::::   |       |.    ':|
  1140.         |       |       |       |       |::::   |       |::.    |
  1141.         + ----- +       + ----- +       - ----- +       + ----- -
  1142.  
  1143.     The result of the marching cubes algorithm is a smooth surface
  1144.     that approximates the isosurface that is constant along a given
  1145.     threshold. This is useful for displaying a volume of oil in a
  1146.     geological volume, for example.
  1147.  
  1148.  
  1149. ----------------------------------------------------------------------
  1150.  
  1151. Subject: 42) What is the status of the patent on the "marching cubes" algorithm?
  1152.  
  1153.  
  1154. ----------------------------------------------------------------------
  1155.  
  1156. Subject: 43) How do I do a hidden surface test (backface culling) with 3d points?
  1157.  
  1158.     Just define all points of all polygons in clockwise order.
  1159.  
  1160.             c = (x3*((z1*y2)-(y1*z2))+
  1161.                 (y3*((x1*z2)-(z1*x2))+
  1162.                 (z3*((y1*x2)-(x1*y2))+
  1163.  
  1164.     x1,y1,z1, x2,y2,z2, x3,y3,z3 = the first three points of the
  1165.     polygon.
  1166.  
  1167.     If c is positive the polygon is visible. If c is negative the
  1168.     polygon is invisible (or the other way).
  1169.  
  1170.  
  1171. ----------------------------------------------------------------------
  1172.  
  1173. Subject: 44) How do I do a hidden surface test (backface culling) with 2d points?
  1174.  
  1175.     c = (x1-x2)*(y3-y2)-(y1-y2)*(x3-x2)
  1176.  
  1177.     x1,y1, x2,y2, x3,y3 = the first three points of the polygon.
  1178.  
  1179.     If c is positive the polygon is visible. If c is negative the
  1180.     polygon is invisible (or the other way).
  1181.  
  1182.  
  1183. ----------------------------------------------------------------------
  1184.  
  1185. Subject: 45) Where can I find graph layout algorithms?
  1186.  
  1187.     See the paper by Eades and Tamassia, "Algorithms for Drawing
  1188.     Graphs: An Annotated Bibliography," Tech Rep CS-89-09, Dept.  of
  1189.     CS, Brown Univ, Feb. 1989.
  1190.  
  1191.     A revised version of the annotated bibliography on graph drawing
  1192.     algorithms by Giuseppe Di Battista, Peter Eades, and Roberto
  1193.     Tamassia is now available from
  1194.  
  1195.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.tex.Z and
  1196.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.ps.Z
  1197.  
  1198.  
  1199. ----------------------------------------------------------------------
  1200.  
  1201. Subject: 46) Where can I find algorithms for 2D collision detection?
  1202.  
  1203.  
  1204. ----------------------------------------------------------------------
  1205.  
  1206. Subject: 47) Where can I find algorithms for 3D collision detection?
  1207.  
  1208.     Check out "proxima", from Purdue, which is a C++ library for 3D
  1209.     collision detection for arbitrary polyhedra.  It's a nice system;
  1210.     the algorithms are sophisticated, but the code is of modest size.
  1211.  
  1212.     There's a copy in ftp://shasta.stanford.edu/pub/nagle/proxima; it
  1213.     may not be the latest version.
  1214.  
  1215.  
  1216. ----------------------------------------------------------------------
  1217.  
  1218. Subject: 48) 3D Noise functions and turbulence in Solid texturing.
  1219.  
  1220.     See:
  1221.         ftp://gondwana.ecr.mu.oz.au/pub/siggraph92_C23.shar
  1222.         ftp://ftp.cis.ohio-state.edu/siggraph92/siggraph92_C23.shar
  1223.  
  1224.     In it there are implementations of Perlin's noise and turbulence
  1225.     functions, (By the man himself) as well as Lewis' sparse
  1226.     convolution noise function (by D. Peachey) There is also some of
  1227.     other stuff in there (Musgrave's Earth texture functions, and some
  1228.     stuff on animating gases by Ebert).
  1229.  
  1230.  
  1231. ----------------------------------------------------------------------
  1232.  
  1233. Subject: 49) How do I perform basic viewing in 3d?
  1234.  
  1235.     We describe the shape and position of objects using numbers,
  1236.     usually (x,y,z) coordinates. For example, the corners of a cube
  1237.     might be {(0,0,0), (1,0,0), (1,1,0), (0,1,0), (0,0,1), (1,0,1),
  1238.     (1,1,1), (0,1,1)}. A deep understanding of what we are saying with
  1239.     these numbers requires mathematical study, but I will try to keep
  1240.     this simple. At the least, we must understand that we have
  1241.     designated some point in space as the origin--coordinates
  1242.     (0,0,0)--and marked off lines in 3 mutually perpendicular
  1243.     directions using equally spaced units to give us (x,y,z) values.
  1244.     It might be helpful to know if we are using 1 to mean 1 foot, 1
  1245.     meter, or 1 parsec; the numbers alone do not tell us.
  1246.  
  1247.     A picture on a screen is two steps removed from the 3D world it
  1248.     depicts. First, it is a 2D projection; and second, it is a finite
  1249.     resolution approximation to the infinitely precise projection. I
  1250.     will ignore the approximation (sampling) for now. To know what the
  1251.     projection looks like, we need to know where our viewpoint is, and
  1252.     where the plane of the projection is, both in the 3D world. Think
  1253.     of it as looking out a window into a scene. As artists discovered
  1254.     some 500 years ago, each point in the world appears to be at a
  1255.     point on the window. If you move your head or look out a different
  1256.     window, everything changes. When the mathematicians understood
  1257.     what the artists were doing, they invented perspective geometry.
  1258.  
  1259.     If your viewpoint is at the origin--(0,0,0)--and the window sits
  1260.     parallel to the x-y plane but at z=1, projection is no more than
  1261.     (x,y,z) in the world appears at (x/z,y/z,1) on the plane. Distant
  1262.     points will have large z values, causing them to shrink in the
  1263.     picture. That's perspective.
  1264.  
  1265.     The trick is to take an arbitrary viewpoint and plane, and
  1266.     transform the world so we have the simple viewing situation.
  1267.     There are two steps: move the viewpoint to the origin, then move
  1268.     the viewplane to the z=1 plane. If the viewpoint is at (vx,vy,vz),
  1269.     transform every point by the translation (x,y,z) -->
  1270.     (x-vx,y-vy,z-vz). This includes the viewpoint and the viewplane.
  1271.     Now we need to rotate so that the z axis points straight at the
  1272.     viewplane, then scale so it is 1 unit away.
  1273.  
  1274.     After all this, we may find ourselves looking out upside- down. It
  1275.     is traditional to specify some direction in the world or viewplane
  1276.     as "up", and rotate so the positive y axis points that way (as
  1277.     nearly as possible if it's a world vector). Finally, we have acted
  1278.     so far as if the window was the entire plane instead of a limited
  1279.     portal. A final shift and scale transforms coordinates in the
  1280.     plane to coordinates on the screen, so that a rectangular region
  1281.     of interest (our "window") in the plane fills a rectangular region
  1282.     of the screen (our "canvas" if you like).
  1283.  
  1284.     I have left out details of how you define and perform the rotation
  1285.     of the viewplane, but I'm sure someone else will be happy to
  1286.     supply those if there is demand. It requires knowing how to
  1287.     describe a plane, and how to rotate vectors to line up. Neither is
  1288.     difficult, but this is already using a lot of net space. One
  1289.     further practical difficulty is the need to clip away parts of the
  1290.     world behind us, so -(x,y,z) doesn't pop up at (x/z,y/z,1).
  1291.     (Notice the mathematics of projection alone would allow that!) But
  1292.     all the viewing transformations can be done using translation,
  1293.     rotation, scale, and a final perspective divide. If a 4x4
  1294.     homogeneous matrix is used, it can represent everything needed,
  1295.     which saves a lot of work.
  1296.  
  1297.  
  1298. ----------------------------------------------------------------------
  1299.  
  1300. Subject: 50) How can you contribute to this FAQ?
  1301.  
  1302.     Send email to jdstone@ingr.com with your suggestions, possible
  1303.     topics, corrections, or pointers to information.  Remember, I am
  1304.     not an expert on many of these topics.  I'm the editor.
  1305.  
  1306.     Here are some possible topics that may interest many of our
  1307.     readers.
  1308.  
  1309.     Clipping...
  1310.     Splines
  1311.     Nurbs
  1312.     Image Warping/Transformation/Filtering
  1313.     Anti-aliasing
  1314.     Volume Rendering
  1315.     Morphing (synonymous with generalized Warping)
  1316.     MPEG
  1317.     JPEG
  1318.     Z-buffer/A-buffer/etc.
  1319.     interpolation (linear, spline, fft, etc.)
  1320.     Modeling tricks  (fractal mountains, trees, seashells)
  1321.  
  1322.     Surfaces
  1323.     Ray Tracing
  1324.     Reflection/Refraction
  1325.  
  1326.     1) Computing the minimum bounding boxes of various geometric
  1327.        elements such as circular arcs, parabolas, clothoids, splines,
  1328.        etc.  What is the most efficient way to do them for the
  1329.        following cases:
  1330.  
  1331.         i)  The boxes are all orthogonal to the XY plane;
  1332.         ii) The boxes is oriented such that the smallest area
  1333.             rectangular bounding boxes are computed.
  1334.  
  1335.     2) What is the most efficient way to tell if a polygon crosses
  1336.        itself?  i.e. without intersecting every edge with every edge.
  1337.  
  1338. ----------------------------------------------------------------------
  1339.  
  1340. Subject: 51) Contributors.  Who made this all possible.
  1341.  
  1342.     andrewfg@aifh.ed.ac.uk (Andrew Fitzgibbon)
  1343.     atae@spva.ph.ic.ac.uk (Ata Etemadi)
  1344.     atsao@tkk.win.net (Anson Tsao)
  1345.     barber@geom.umn.edu (Brad Barber)
  1346.     bromage@mundil.cs.mu.OZ.AU (Andrew James Bromage)
  1347.     cek@Princeton.EDU (Craig Kolb)
  1348.     fritz@riverside.MR.Net (Fritz Lott)
  1349.     hollasch@kgc.com (Steve Hollasch)
  1350.     jens_alfke@powertalk.apple.com (Jens Alfke)
  1351.     karsten@addx.stgt.sub.org (Karsten Weiss)
  1352.     lhf@visgraf.impa.br (Luiz Henrique de Figueiredo)
  1353.     orourke@cs.smith.edu (Joseph O'Rourke)
  1354.     paik@mlo.dec.com (Samuel S. Paik)
  1355.     sammy@icarus.smds.com (Samuel Murphy)
  1356.     sanguish@digifix.com (Scott Anguish)
  1357.     shoemake@graphics.cis.upenn.edu (Ken Shoemake)
  1358.     slin@esri.com (Sum Lin)
  1359.     spl@szechuan.ucsd.edu (Steve Lamont)
  1360.     weilej@rpi.edu (Jason Weiler)
  1361.  
  1362.  
  1363. $Id: algorithms,v 1.14 1994/09/29 00:54:31 jdstone Exp $
  1364.  
  1365. -- 
  1366. ----------------------------------------------------------------------
  1367. Jon Stone                             Intergraph Corporation
  1368. jdstone@ingr.com                      Boulder, CO
  1369. ----------------------------------------------------------------------
  1370.  
  1371.